from tools.log import log
from tools.databus.bus import workFlow
from plugin.web.flask_app import flaskPluginRegist,FlaskTask
from plugin.task.infraredTrack import carTaskPluginRegist
from plugin.rec.img_get import imgGetPluginRegist
import multiprocessing as mp
from plugin.task_type import TaskType

if __name__ == "__main__":
    htop = "127.0.0.1"
    port = 8080
    state_dict = mp.Manager().dict({"TASK": True})
    q_ipc_src = mp.Manager().Queue(1)
    q_ipc_infer = mp.Manager().Queue(1)
    q_csi_src = mp.Manager().Queue(1)
    q_csi_infer = mp.Manager().Queue(1)
    q_send = mp.Manager().Queue(2)
    stopFlag = mp.Manager().Value('i', 0)

    mapOpenPlugin = dict()
    mapClosePlugin = dict()

    mapOpenPlugin[TaskType.IMAGE_GET_TASK] = (imgGetPluginRegist,
                                              (state_dict,
                                               q_ipc_src, q_ipc_infer,
                                               q_csi_src, q_csi_infer))
    mapOpenPlugin[TaskType.CAR_TASK] = (carTaskPluginRegist,
                                        (state_dict, stopFlag, q_send))
    mapOpenPlugin[TaskType.FLASK_TASK] = (flaskPluginRegist,
                                          (htop, port,
                                           state_dict,
                                           q_csi_infer, q_ipc_infer,
                                           stopFlag, q_send))

    for plugin in mapOpenPlugin:
        print(plugin)
        taskFunc, taskArgs = mapOpenPlugin[plugin]
        taskFunc(*taskArgs)  # 提交任务
        workFlow.busStart()
